use std::sync::Arc;

use axum::{
    Router, 
    body::{Body, Bytes},
    Form, extract::{Path, extractor_middleware}, response::{IntoResponse, Response}, Json, http::Request, middleware::{Next, self, from_extractor}, Extension, routing::{post, get},
};



use axum_side::{
    app::{self, config, init},
    config::Config, handler::{auth, helper}, model::AppState, form::{self, AdminLogin, EmptyVo}, middleware::authed::Authed,
};

use reqwest::StatusCode;
use serde_json::{json, Value};
use tower_http::add_extension::AddExtensionLayer;


/// 程序入口
#[tokio::main]
async fn main() {
    // 1. 初始化配置
    config();

    // 2. 上下文初始化
    init();

    // 3. 路由注册
    let app_router = app::routers();

    // app banner
    let banner = r#"
                       __  __  __ 
    /\ \_//  \|\/|    (_ ||  \|_  
   /--\/ \\__/|  |    __)||__/|__ 
                                  "#;

    println!("{}", banner);
    
    // 获取 web服务配置
    let web_config = &app::get_config::<Config>().web;
    tracing::info!("app 启动成功{}...", &web_config.addr);

    // 4. 服务启动
    axum::Server::bind(&web_config.addr.parse().unwrap())
    .serve(app_router.into_make_service())
        .await
        .unwrap();
}
